package com.ruoyi.supplier.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.supplier.domain.vo.PurchaseAmountVo;
import com.ruoyi.supplier.domain.bo.PurchaseAmountBo;
import com.ruoyi.supplier.service.IPurchaseAmountService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 采购单费用结算控制器
 * 前端访问路由地址为:/supplier/amount
 *
 * @author ruoyi
 * @date 2023-09-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/purchaseAmount")
public class PurchaseAmountController extends BaseController {

    private final IPurchaseAmountService iPurchaseAmountService;

    /**
     * 查询采购单费用结算列表
     */
    @SaCheckPermission("supplier:amount:list")
    @GetMapping("/list")
    public TableDataInfo<PurchaseAmountVo> list(PurchaseAmountBo bo, PageQuery pageQuery) {
        return iPurchaseAmountService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出采购单费用结算列表
     */
    @SaCheckPermission("supplier:amount:export")
    @Log(title = "采购单费用结算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PurchaseAmountBo bo, HttpServletResponse response) {
        List<PurchaseAmountVo> list = iPurchaseAmountService.queryList(bo);
        ExcelUtil.exportExcel(list, "采购单费用结算", PurchaseAmountVo.class, response);
    }

    /**
     * 获取采购单费用结算详细信息
     *
     * @param purchaseAmountId 主键
     */
    @SaCheckPermission("supplier:amount:query")
    @GetMapping("/{purchaseAmountId}")
    public R<PurchaseAmountVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer purchaseAmountId) {
        return R.ok(iPurchaseAmountService.queryById(purchaseAmountId));
    }

    /**
     * 新增采购单费用结算
     */
    @SaCheckPermission("supplier:amount:add")
    @Log(title = "采购单费用结算", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PurchaseAmountBo bo) {
        return toAjax(iPurchaseAmountService.insertByBo(bo));
    }

    /**
     * 修改采购单费用结算
     */
    @SaCheckPermission("supplier:amount:edit")
    @Log(title = "采购单费用结算", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PurchaseAmountBo bo) {
        return toAjax(iPurchaseAmountService.updateByBo(bo));
    }

    /**
     * 删除采购单费用结算
     *
     * @param purchaseAmountIds 主键串
     */
    @SaCheckPermission("supplier:amount:remove")
    @Log(title = "采购单费用结算", businessType = BusinessType.DELETE)
    @DeleteMapping("/{purchaseAmountIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Integer[] purchaseAmountIds) {
        return toAjax(iPurchaseAmountService.deleteWithValidByIds(Arrays.asList(purchaseAmountIds), true));
    }
}
